/* 用户名格式判断 */
function myFunction1(value) {
    // 正则规则
    //var emailReg=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    var telReg=/^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
    //var pwdReg=/^[a-zA-Z0-9]{6,20}$/;
    //var idCardReg = /^\d{15}|\d{18}$/;
    //var useNameReg = /^[a-zA-Z0-9_-]{4,16}$/;
    //var addressReg = /^\w+$/;
    var username = document.getElementById("username");
    if(value == "") {
        username.innerText = "用户名不能为空";
    } else if(!telReg.test(value.trim())) {
        username.innerText = "手机号格式不正确";
    } else {
        username.innerText = "";
    }

}
var password1;
/* 密码格式判断 */
function myFunction2(value) {
    // 正则规则
    var pwdReg=/^[a-zA-Z0-9]{6,20}$/;
    
    var password = document.getElementById("password");
    if(value == "") {
        password.innerText = "密码不能为空";
    }else if(!pwdReg.test(value.trim())) {
        password.innerText = "密码格式不正确";
    }else{
        password.innerText = "";
    }
    password1 = document.getElementById("pwd").value;
}

/* 确认密码格式判断 */
function myFunction3(value){
    
    var checkpass = document.getElementById("checkpass");
    if(value == ""){
        checkpass.innerText = "确认密码不能为空";
    }else if(value == password1){
        checkpass.innerText = "";
    }else{
        checkpass.innerText = "与设置密码不一致，请重新输入！";
    }
}
function doButton(){
    // debugger;
    var username = document.getElementById("user").value;
    var password = document.getElementById("pwd").value;
    var pwd=password;
    if (username==""||username==null){
        alert("请输入用户名！");
        return false;
    }else if (password==""||password==null){
        alert("请输入密码！");
        return false;
    }else if (pwd==""||pwd==null){
        alert("请输入确认密码！");
        return false;
    }
    // alert("注册中");
    $.ajax({
        url: "/doRegit",
        type : "POST",
        data :{
            "userName":username,
            "userPassword": password,
            },
        dataType: "json",
        async: false,
        success: function (data){
            // debugger;
            console.log("状态码为："+data.status)
            if (data.status==200){
                // debugger;
                alert("注册成功！");
                window.location.href="/aboutme";
            }else {
                alert("用户名已被占用！");
                window.location.href="/regit";
            }
        }
    })
    // alert("注册成功");
}